package models

import (
	"crypto/md5"
	"fmt"
	"gorm.io/gorm"
)

type User struct {
	gorm.Model
	UserName     string `gorm:"type:varchar(50)"`
	UserAccount  string `gorm:"type:varchar(50)"`
	UserPassword string `gorm:"type:varchar(32)"`
}

func (u *User) GetUserByUserAccount() error {
	return DB.Where("user_account = ?", u.UserAccount).Limit(1).Find(&u).Error
}
func StrToMD5(str string) (MD5 string) {
	data := []byte(str)
	has := md5.Sum(data)
	MD5 = fmt.Sprintf("%x", has) //将[]byte转成16进制

	fmt.Println(MD5)
	return MD5
}
func (u *User) PasswordBool(password string) bool {
	return !(u.UserPassword == StrToMD5(password))
}
